#include <stdafx.h>
#include "dynmdm.h"





IMPLEMENT_DYNAMIC(CDynMultiDocTemplate, CMultiDocTemplate)

CDynMultiDocTemplate::CDynMultiDocTemplate(HINSTANCE hInst, UINT nIDResource, CRuntimeClass* pDocClass, CRuntimeClass* pFrameClass, CRuntimeClass* pViewClass)
: CMultiDocTemplate(nIDResource, pDocClass, pFrameClass, pViewClass)
{
    m_hInst = hInst;
    m_ResourceID = nIDResource;
}

CDynMultiDocTemplate::~CDynMultiDocTemplate()
{

}

void CDynMultiDocTemplate::LoadTemplate()
{
    // call the base class member after switching the resource to the DLL, if this is a DLL document type
    HINSTANCE    hOld;

    hOld = AfxGetResourceHandle();            // save
    AfxSetResourceHandle(m_hInst);            // set
    CMultiDocTemplate::LoadTemplate();        // now get from correct resources!
    AfxSetResourceHandle(hOld);            // restore
}

CDocument* CDynMultiDocTemplate::OpenDocumentFile(LPCTSTR lpszPathName, BOOL bMakeVisible)
{
    // switch to the correct resources and then resturn the document
    CDocument    *pDoc = NULL;
    HINSTANCE    hOld;

    hOld = AfxGetResourceHandle();            // save
    AfxSetResourceHandle(m_hInst);            // set
    pDoc = CMultiDocTemplate::OpenDocumentFile(lpszPathName, bMakeVisible);
    AfxSetResourceHandle(hOld);            // restore
    return pDoc;
}

#ifdef _DEBUG
void CDynMultiDocTemplate::AssertValid() const
{
    CMultiDocTemplate::AssertValid();
}

void CDynMultiDocTemplate::Dump(CDumpContext& dc) const
{
    CMultiDocTemplate::Dump(dc);
}
#endif
